package com.fun.feifun.modules.business.controller;
import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
import com.fun.feifun.modules.business.service.IBusinessOrderLogService;
import com.fun.feifun.modules.business.model.BusinessOrderLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.fun.feifun.base.result.Result;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;

import java.util.List;

/**
 * <p>
 * 业务订单日志 前端控制器
 * </p>
 *
 * @author wkf
 * @since 2024-06-20
 */
@RestController
@Api(value = "/business/business-order-log", tags = "业务订单日志")
@Slf4j
@RequestMapping("/business/business-order-log")
@SaCheckLogin()
public class BusinessOrderLogController {


    @Autowired
    private IBusinessOrderLogService service;

    /**
     * 获取分页
     */
    @PostMapping("/page")
    @ApiOperation(value = "获取分页信息")
    public Result<Page<BusinessOrderLog>> page(@RequestParam(name = "page", defaultValue = "1") int index,@RequestParam(name = "size", defaultValue = "10") int size){
        QueryWrapper<BusinessOrderLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().orderByDesc(BusinessOrderLog::getCreateTime);
        Page page = new Page(index,size);
        service.page(page,queryWrapper);
        return Result.success(page);
    }



    /**
     * 添加数据
     */
    @PostMapping(value = "/save")
    @ApiOperation(value = "添加或者保存")
    public Result save(@RequestBody BusinessOrderLog item){
        if(service.saveOrUpdate(item)){
         return Result.success("数据添加成功！");
        }
        return Result.err("数据添加成功！");
    }



    /**
     * 获取全部数据
     */
    @GetMapping("/all")
    @ApiOperation(value = "获取全部数据")
    public Result<List<BusinessOrderLog>> getAll(){
        List<BusinessOrderLog> all = service.list();
        return Result.success(all);
    }

    /**
     * 获取分页
     */
    @PostMapping("/getList")
    @ApiOperation(value = "获取日志信息列表")
    public Result<List<BusinessOrderLog>> getList(@RequestParam(name = "orderId") Long orderId){
        QueryWrapper<BusinessOrderLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BusinessOrderLog::getOrderId,orderId) ;
        List<BusinessOrderLog> list = service.list(queryWrapper);
        return Result.success(list);
    }

}

